## 计算净保费np_、pvnp、pvdb1~5字段
## 净保费 np_
np_ = (ppp_ - expense) * prem_cv

## 净保费现值 pvnp
A = sum(dx * (ppp_ - expense))
pvnp = prem_cv * A/dx

## pvdb1
## 第一保单年度
policy_year = 1
A = sum(ci_cx_ * db1)
B = prem * ci_cx_ * (1 + interest_rate_cv)^0.25
C = sa * db1 * ci_cx_ * (1 + interest_rate_cv)^-0.25
pvdb1 = (sa * A + 0.5(B + C)) / dx

## 第二及后续保单年度
policy_year >= 2
A = sum(ci_cx_ * db1)
pvdb1 = sa * A/dx

## pvdb1
## 第一保单年度
policy_year = 1
A = sum(ci_cx_ * db2)
B =prem * ci_cx_ * (1 + interest_rate_cv)^0.25
C = sa * db2 * ci_cx_ * (1 + interest_rate_cv)^-0.25
pvdb2 = (sa * A + 0.5(B + C)) / dx

## 第二及后续保单年度
policy_year >= 2

A = sum(ci_cx_ * db2)
pvdb2 = sa * A/dx

A = sum(dx * db3)
pvdb3 = sa * A/dx

A = sum(cx_ * db4)
pvdb4 = sa * A/dx

A = sum(ci_cx_ * db5)
pvdb5 = sa * A/dx

## 保单价值准备金pvr、rt字段
## pvr
pvr = sum(pvdb1 + pvdb2 + pvdb3 + pvdb4 + pvdb5) - pvnp

## rt

IF(PPP=1,1,IF(policy_year>=MIN(20,PPP),1,0.8+policy_year*0.8/MIN(20,PPP)))

IF(PPP=1,1,IF(policy_year>=MIN(20,PPP),1,0.8+policy_year*0.8/MIN(20,PPP)))*(policy_year<=BPP)

## 计算修匀净保费np、生存金sur_ben、cv_1b字段
## 修匀净保费np
np = lag(rt,1) * round(np_,4)

## 生存金sur_ben
sur_ben = db3 * sa

## cv_1b
cv_1b = greatest(pvr - lead(sur_ben,1))

## 计算现金价值年末（生存给付前）cv_1a
cv_1a = cv_1b + lead(sur_ben,1)

## 计算现金价值年中cv_2
cv_2 = (lag(rt,1) * np_ + lag(cv_1b,1) + cv_1a) / 2